package com.yx.shop.web.controller;

import com.yx.shop.utils.Base64Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Classname PayController
 * @Description TODO:
 * @Date 2021/05/10 10:46
 * @Created by yx
 */
@WebServlet("/payController")
public class PayController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String oid = request.getParameter("orderId");
        System.out.println("payController======================>"+oid);
        Double price = Double.valueOf(request.getParameter("price"));
//        String result_json = "{\"result\":{\"appid\":\"wx632c8f211f8122c6\",\"bank_type\":\"CFT\",\"cash_fee\":\"1\",\"fee_type\":\"CNY\",\"is_subscribe\":\"Y\",\"mch_id\":\"1497984412\",\"nonce_str\":\"1631171182\",\"openid\":\"oUuptwrJudIfdihz1Z_T1AciMahs\",\"out_trade_no\":\"" + oid + "\",\"result_code\":\"SUCCESS\",\"return_code\":\"SUCCESS\",\"sign\":\"5C7314AA4EB21772B42DBBCD65E56ACF\",\"time_end\":\"" + System.currentTimeMillis() + "\",\"total_fee\":\"" + price + "\",\"trade_type\":\"NATIVE\",\"transaction_id\":\"4200000065201802078895888133\"},\"type\":0}";
        String result_json = "{\"result\":{\"appid\":\"wx632c8f211f8122c6\",\"bank_type\":\"CFT\",\"cash_fee\":\"1\",\"fee_type\":\"CNY\",\"is_subscribe\":\"Y\",\"mch_id\":\"1497984412\",\"nonce_str\":\"1631171182\",\"openid\":\"oUuptwrJudIfdihz1Z_T1AciMahs\",\"out_trade_no\":\"" + oid + "\",\"result_code\":\"SUCCESS\",\"return_code\":\"SUCCESS\",\"sign\":\"5C7314AA4EB21772B42DBBCD65E56ACF\",\"time_end\":\"" + System.currentTimeMillis() + "\",\"total_fee\":\"" + price + "\",\"trade_type\":\"NATIVE\",\"transaction_id\":\"4200000065201802078895888133\"},\"type\":0}";
        //调用回调地址
        response.sendRedirect("http://localhost:8080/order?method=payCheck&result=" + Base64Utils.encode(result_json));

    }
}
